<%@ include file="/WEB-INF/common/taglibs.jsp"%>
<script type="text/javascript">
$(function() {
	var prjId = $("#prjId"), prjDesc = $("#prjDesc");
	$('#editDialog').dialog({
		autoOpen: false,
		width: 480,
		buttons: {
			'Save': function() {
				$.ajax({
					url: '/ajax/admin/updatePrjDesc.do?prjId=' + prjId.val() + '&prjDesc=' + prjDesc.val(),
					type: 'POST',
					timeout: 10000,
					error: function(){
						$("#message").addClass("ui-state-error");
						$("#message").html("<span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span><strong></strong>Update failed!");
						setTimeout(function(){$("#message").html("").removeClass("ui-state-error");},5000);
					},
					success: function(){
						$("#message").addClass("ui-state-highlight");
						$("#message").html("<span class='ui-icon ui-icon-info' style='float: left; margin-right: .3em;'></span><strong></strong>Update successfully!");
						setTimeout(function(){$("#message").html("").removeClass("ui-state-highlight");},5000);
						$("#" + prjId.val() + "_desc").html(prjDesc.val());
					}
				});
				$(this).dialog('close');
			},
			Cancel: function() {$(this).dialog('close');}
		},
		close: function() {}
	});
});

function edit(id){
	$("#prjId").val(id);
	var name = $("#" + id + "_name").html();
	$('#editDialog').dialog({
		title:'Edit Project Description - ' + name,
	});
	$('#editDialog').dialog('open');
	
	var desc = $("#" + id + "_desc").html();
	$("#prjDesc").val(desc);
	return false;
}
</script>
<div class="items"><c:forEach var="prj" items="${prjs}">
	<div class="item">
	<div class="title"><a
		href="<c:url value="/project.do?id=${prj.id}" />"><font
		id="${prj.id}_name">${prj.name}</font></a>&nbsp;&nbsp;<font
		class="tagFlag">[${prj.tag}]</font></div>
	<div class="description"><font id="${prj.id}_desc">${prj.description}</font>&nbsp;<a
		href="#" onclick="edit('${prj.id}')"><img src="/images/edit.png" /></a><br />
	<a href="${prj.url}" target="_blank">${prj.url}</a>&nbsp;&nbsp;<a
		href="<c:url value="/project.do?id=${prj.id}" />"><c:choose>
		<c:when test="${prj.linkQuantity eq null || prj.linkQuantity == 0}">no</c:when>
		<c:otherwise>${prj.linkQuantity}</c:otherwise>
	</c:choose>links&nbsp;shared</a>&nbsp;&nbsp;<a href="#"
		onclick="shareWithCategory('Link','prj','${prj.id}')"><img
		src="<c:url value="/images/share-a-link.png" />" alt="share a link" /></a></div>
	</div>
</c:forEach></div>

<div id="editDialog">
<form><input type="hidden" name="prjId" id="prjId" value=""><textarea
	name="prjDesc" id="prjDesc" style="width: 450px; height: 160px;"
	class="text ui-widget-content"></textarea></form>
</div>
